package com.yic.module.base.dal.mysql.factory;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.factory.FactoryDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.factory.vo.*;

/**
 * 工厂 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface FactoryMapper extends BaseMapperX<FactoryDO> {

    default PageResult<FactoryDO> selectPage(FactoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FactoryDO>()
                .likeIfPresent(FactoryDO::getName, reqVO.getName())
                .eqIfPresent(FactoryDO::getCode, reqVO.getCode())
                .eqIfPresent(FactoryDO::getStatus, reqVO.getStatus())
                .eqIfPresent(FactoryDO::getSort, reqVO.getSort())
                .eqIfPresent(FactoryDO::getRemark, reqVO.getRemark())
                .orderByDesc(FactoryDO::getId));
    }

    default List<FactoryDO> selectList(FactoryExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FactoryDO>()
                .likeIfPresent(FactoryDO::getName, reqVO.getName())
                .eqIfPresent(FactoryDO::getCode, reqVO.getCode())
                .eqIfPresent(FactoryDO::getStatus, reqVO.getStatus())
                .eqIfPresent(FactoryDO::getSort, reqVO.getSort())
                .eqIfPresent(FactoryDO::getRemark, reqVO.getRemark())
                .orderByDesc(FactoryDO::getId));
    }

    default FactoryDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<FactoryDO>()
                .eqIfPresent(FactoryDO::getCode, code));
    }

    default FactoryDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<FactoryDO>()
                .eqIfPresent(FactoryDO::getName, name));
    }

    default List<FactoryDO> selectList(Collection<Long> ids, Collection<Integer> statuses){
        return selectList(new LambdaQueryWrapperX<FactoryDO>()
                .inIfPresent(FactoryDO::getId, ids)
                .inIfPresent(FactoryDO::getStatus, statuses));
    }
}
